import matplotlib.pyplot as plt
import numpy as np
import os

def cr():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    cr_data = [0.8720028398141417, 0.8904029948898912, 0.9432786953936813, 0.9048858644668853, 0.9416265642617491, 0.9416265642617491, 0.9499150282804846, 0.741035798021584, 0.9497557941913973, 0.8678028681838025, 0.4941896787986099, 0.4941896787986099]
    plt.bar(x_data,cr_data,color="deepskyblue",label="Average Completion Rate")

    #line
    ave_us_data = [0.7828938000000001, 0.7794775999999999, 0.8477137999999997, 0.8000318, 0.8406368000000001, 0.8406368000000001, 0.8510090000000001, 0.7817553999999999, 0.8519276000000002, 0.7497684, 0.4458261999999999, 0.44564620000000005]
    worst_us_data =  [0.78177, 0.77579, 0.84562, 0.79834, 0.83687, 0.83687, 0.84817, 0.78079, 0.84911, 0.74789, 0.4425, 0.44226]
    ave_Comp_ratio = [0.8690998101708461, 0.8653074455212533, 0.9410572706786113, 0.8881249098033992, 0.9332010079817056, 0.9332010079817056, 0.944715311774958, 0.8678360586583186, 0.9457350606676214, 0.832326905784794, 0.49491701912722996, 0.4947171989653754]
    worst_Comp_ratio =  [0.8678522662936691, 0.8612137964720641, 0.9387329181514414, 0.8862468223043705, 0.9290194380613004, 0.9290194380613004, 0.9415637037777111, 0.8667643565235732, 0.9426072090673949, 0.8302416713846427, 0.49122456455856395, 0.49095813767609153]
    plt.plot(x_data, ave_us_data, color = "sandybrown", marker='o', ms=3, label="ave_us")
    plt.plot(x_data, worst_us_data, color = "crimson", marker='o', ms=3, label="worst_us")
    plt.plot(x_data, ave_Comp_ratio, color = "plum", marker='o', ms=3, label="ave_compratio")
    plt.plot(x_data, worst_Comp_ratio, color = "indigo", marker='o', ms=3, label="worst_compratio")
    plt.legend()
    plt.title('Completion rate & US & CompRatio')
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    cr()
        
